package com.vuej.entity;

import com.vuej.core.*;
import lombok.Data;

import java.nio.charset.StandardCharsets;

@Data
public class VueConfiguration {


    private VueFileParser fileParser;

    private VueRender render;

    private ScriptEnvironment scriptEnvironment;

    /**
     * vue文件的编码格式，默认utf-8
     */
    private String vueFileCharset = StandardCharsets.UTF_8.displayName();

    private boolean init;


    public void init() throws Exception {
        if(fileParser == null){
            throw new IllegalStateException("fileParser is null");
        }
        if(render == null){
            throw new IllegalStateException("render is null");
        }
        if(scriptEnvironment == null){
            throw new IllegalStateException("scriptEnvironment is null");
        }
        if(!init){
            init = true;
            render.init(scriptEnvironment);
        }
    }

    public void checkInit(){
        if(!init){
            throw new IllegalStateException("VueConfig.init() must call");
        }
    }


    public static VueConfiguration getDefault(){
        VueConfiguration vueConfig = new VueConfiguration();
        vueConfig.fileParser = new DefaultVueFileParser();
        vueConfig.render = new DefaultVueRender();
        vueConfig.scriptEnvironment = new ScriptEnvironment();
        return vueConfig;
    }


}
